package com.huoniu.api.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.huoniu.api.entity.Role;
import com.huoniu.api.mapper.RoleMapper;
import com.huoniu.api.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @类 名： RoleServiceImpl <br/>
 * @描 述： <br/>
 * @日 期： 2020/9/4 14:05<br/>
 * @作 者： 侯建军<br/>
 * @版 本： 1.0.0
 * @since JDK 1.8
 */
@Service
public class RoleServiceImpl implements RoleService {
    @Autowired
    private RoleMapper roleMapper;

    @Override
    public boolean insert(Role role) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("role_name", role.getRoleName());
        List<Role> roles = roleMapper.selectList(queryWrapper);
        if (roles.size() <= 0) {
            roleMapper.insert(role);
            return true;
        }
        return false;
    }

    @Override
    public boolean delete(Long id) {
        if(roleMapper.deleteById(id)>0){
            return true;
        }
        return false;
    }

    @Override
    public boolean update(Role role) {
       if(roleMapper.updateById(role)>0){
           return true;
       }
        return false;
    }
}
